/** Implementation of PLset Class.
 * @file 
 * @author Jeremy Schultz
 */
#include "PLset.h"
#include <iostream>


using namespace std;

//-----------------------------------------------------------------------------
// Constructor
PLset::PLset()  {
}

//-----------------------------------------------------------------------------
// Constructor
PLset::PLset(PLset *s1, PLset *s2)  {
	vector<Token*> temp1;
	vector<Token*> temp2;

	temp1 = s1->Set();
	temp2 = s2->Set();

	set.insert(set.end(), temp1.begin(), temp1.end() );
	set.insert(set.end(), temp2.begin(), temp2.end() );
}


//-----------------------------------------------------------------------------
// Add a Token to the set
void PLset::add(Token::Token *terminal)	{
	set.push_back(terminal);
}

//-----------------------------------------------------------------------------
// Getter - set
vector<Token*> PLset::Set()	{
	return set;
}


//-----------------------------------------------------------------------------
// Check if set has the token
bool PLset::has(Token::Token *token)	{
	for (unsigned int i=0; i < set.size(); i++)	{
		if (token->Type() == set[i]->Type() )	{
			if (set[i]->Type() == Token::KEYWORD)	{
				if (( WORD(set[i]) )->Lex() == ( WORD(token) )->Lex() )	{
					return true;
				}
			}else	{

				return true;
			}
		}
	}
	return false;
}

//-----------------------------------------------------------------------------
// toString
string PLset::toString()	{
	stringstream ss;

	ss << "set: " ;
	for (unsigned int i=0; i < set.size(); i++)	{
		if (set[i]->Type() == Token::NUMBER)	{
			ss << "(" << ( NUMERIC(set[i]))->toString() << ") ";
		}else if (set[i]->Type() == Token::ID)	{
			ss << "(" << ( WORD(set[i]))->toString() << ") ";
		}else if (set[i]->Type() == Token::KEYWORD)	{
			ss << "(" << ( WORD(set[i]))->toString() << ") ";
		}else	{
			ss << "(" << set[i]->toString() << ") ";
		}
	}
	ss << endl;

	return ss.str();
}


